package com.example.jizhangben;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;

import com.example.jizhangben.databinding.ActivityMainBinding;
import com.example.jizhangben.databinding.FragmentZhiFuBaoBinding;

import java.security.SecurityPermission;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        Objects.requireNonNull(getSupportActionBar()).setTitle("基础信息采集");
        sp = getSharedPreferences("xinxi", Context.MODE_PRIVATE);
        if (sp.getBoolean("ye",true)){
            binding.tijiao.setOnClickListener(v -> {
                //信息存储
                SharedPreferences.Editor editor = sp.edit();

                editor.putString("name",binding.name.getText().toString());
                editor.putBoolean("yan",binding.nochou.isChecked());
                editor.putString("money",binding.money.getText().toString());
                editor.putString("tian",binding.tian.getText().toString());
                editor.commit();
                if (!binding.name.getText().toString().equals("") && !binding.money.getText().toString().equals("") ){
                    Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                    editor.putBoolean("ye",false);
                    editor.commit();
                    startActivity(intent);
                }else {
                    Toast.makeText(getApplicationContext(), "请填写信息", Toast.LENGTH_SHORT).show();
                }

            });
        }else {
            finish();
            Intent intent = new Intent(MainActivity.this,HomeActivity.class);
            startActivity(intent);
        }

    }
}